<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\home\controller;
use think\Loader;
/**
 * Description of Pay
 *
 * @author Administrator
 */
class Pay extends \think\Controller{
    //put your code here
    function weixin(){
        ini_set('date.timezone','Asia/Shanghai');
//        require_once "../extend/weixin/lib/WxPay.Api.php";
//        require_once "../extend/weixin/example/WxPay.NativePay.php";
//        require_once '../extend/weixin/log.php';
          Loader::import('weixin.lib.WxPay',"",".Api.php");
          Loader::import('weixin.example.WxPay',"",".NativePay.php");

        $notify = new \NativePay();
        $input = new \WxPayUnifiedOrder(); //命名空间
        $input->SetBody("weixin");
        $input->SetAttach("微信");
        $input->SetOut_trade_no(date("YmdHis"));
        $input->SetTotal_fee("1");  //订单总金额  单位是分
        $input->SetTime_start(date("YmdHis"));
        $input->SetTime_expire(date("YmdHis", time() + 600));
        $input->SetGoods_tag("test");
        $input->SetNotify_url("SITE_URL.'/index.php/Home/Payment/notifyUrl/pay_code/weixin'");
        $input->SetTrade_type("NATIVE");
        $input->SetProduct_id("123456789");
        $result = $notify->GetPayUrl($input);
        $url2 = $result["code_url"];
        $str = '<div style="margin-left: 10px;color:#556B2F;font-size:30px;font-weight: bolder;">扫描支付模式二</div><br/>'
                . '<img alt="模式二扫码支付" src="http://paysdk.weixin.qq.com/example/qrcode.php?data='.urlencode($url2).'" style="width:150px;height:150px;"/>';
        $this->assign('str',$str);
       return $this->fetch();
    }
}
